package com.ruoyi.security.service.impl;

import cn.hutool.core.util.IdUtil;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.utils.SecurityUtils;
import com.ruoyi.security.domain.AfSafetyEducation;
import com.ruoyi.security.mapper.AfSafetyEducationMapper;
import com.ruoyi.security.service.IAfSafetyEducationService;
import com.ruoyi.system.api.LinkFileServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 安全教育Service业务层处理
 *
 * @author Felix
 * @date 2021-10-12
 */
@Service
public class AfSafetyEducationServiceImpl  extends LinkFileServiceImpl implements IAfSafetyEducationService {
    @Autowired
    private AfSafetyEducationMapper afSafetyEducationMapper;


    /**
     * 查询安全教育
     *
     * @param id 安全教育ID
     * @return 安全教育
     */
    @Override
    public AfSafetyEducation selectAfSafetyEducationById(String id) {
        AfSafetyEducation  afSafetyEducation =  afSafetyEducationMapper.selectAfSafetyEducationById(id);
        afSafetyEducation.setFileList(getFileList(id));
        return afSafetyEducation;
    }

    /**
     * 查询安全教育列表
     *
     * @param afSafetyEducation 安全教育
     * @return 安全教育
     */
    @Override
    public List<AfSafetyEducation> selectAfSafetyEducationList(AfSafetyEducation afSafetyEducation) {
        return afSafetyEducationMapper.selectAfSafetyEducationList(afSafetyEducation);
    }

    /**
     * 新增安全教育
     *
     * @param afSafetyEducation 安全教育
     * @return 结果
     */
    @Override
    public int insertAfSafetyEducation(AfSafetyEducation afSafetyEducation) {
        afSafetyEducation.setId(IdUtil.getSnowflake(0, 0).nextIdStr());
        afSafetyEducation.setCreateTime(DateUtils.getNowDate());
        afSafetyEducation.setCreateBy(SecurityUtils.getUsername());
        linkFile(afSafetyEducation.getFileIdList(), afSafetyEducation.getId());
        return afSafetyEducationMapper.insertAfSafetyEducation(afSafetyEducation);
    }

    /**
     * 修改安全教育
     *
     * @param afSafetyEducation 安全教育
     * @return 结果
     */
    @Override
    public int updateAfSafetyEducation(AfSafetyEducation afSafetyEducation) {
        afSafetyEducation.setUpdateTime(DateUtils.getNowDate());
        afSafetyEducation.setUpdateBy(SecurityUtils.getUsername());
        linkFile(afSafetyEducation.getFileIdList(), afSafetyEducation.getId());
        return afSafetyEducationMapper.updateAfSafetyEducation(afSafetyEducation);
    }

    /**
     * 批量删除安全教育
     *
     * @param ids 需要删除的安全教育ID
     * @return 结果
     */
    @Override
    public int deleteAfSafetyEducationByIds(String[] ids) {
        deleteLinkFile(ids);
        return afSafetyEducationMapper.deleteAfSafetyEducationByIds(ids);
    }

    /**
     * 删除安全教育信息
     *
     * @param id 安全教育ID
     * @return 结果
     */
    @Override
    public int deleteAfSafetyEducationById(String id) {
        return afSafetyEducationMapper.deleteAfSafetyEducationById(id);
    }
}
